package waal.pc.backend.channels;

import waal.pc.backend.dataPoints.DigitalDataPoint;
import waal.pc.backend.module.Module;

public class DigitalChannel extends Channel {

	private DigitalDataPoint lastValue;
	

	public DigitalChannel(Module module, int number, String name, boolean input) {
		super(module, number, name, input, true);
		this.lastValue = new DigitalDataPoint(0,false);
		module.fireChannelEvent(new ChannelEvent(1, this));
	}
	
	public DigitalChannel(Module module, int number, String name) {
		this(module, number,name, true);
	}
			
	public void addValue(double time, boolean value) {
		DigitalDataPoint p = new DigitalDataPoint(time, value);
		this.lastValue = p;
		this.addDataForChannelDataListener(p);
		this.fireChannelChange();
	}
	
	public void setValue(boolean state) {
		DigitalDataPoint p = new DigitalDataPoint(0, state);
		this.lastValue = p;
		this.fireChannelChange();
	}

	public DigitalDataPoint getLastData() {
		return this.lastValue;
	}
	
	public boolean getLastState() {
		return this.lastValue.getState();
	}
	
	public double getLastValue() {
		return this.lastValue.getValue();
	}
}
